package delete;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Calendar;

import javax.swing.JOptionPane;

public class getHtmlTime {

	public static void main(String args[]) {
		getHtmlTime ght = new getHtmlTime();
		ght.coding();
		ght.reCoding();
	}

	private void reCoding() {
		String ss = "1;82=G802<>071D7312341=4";
		StringBuffer a = new StringBuffer();
		int no = 0;
		int no1 = 0;
		char b = (char) 1;
		while (no < ss.length()) {
			no1 = ss.charAt(no) - 47;
			no = no + no1;
			if (b == (char) 1) {
			} else if (b == ss.charAt(no)) {
				no++;
			} else {
				break;
			}
			a.append(ss.charAt(no));
			b = ss.charAt(no);
			if (a.length() > 4) {
				break;
			}
			no++;
		}
		System.out.println(a);
	}

	public void coding() {
		String sTmp = "http://open.baidu.com/special/time/";
		try {
			URL url = new URL(sTmp);

			HttpURLConnection connect = (HttpURLConnection) url
					.openConnection();
			connect.setDoInput(true);

			BufferedReader in = new BufferedReader(new InputStreamReader(
					connect.getInputStream()));

			String line = null;
			long time = 0;
			while ((line = in.readLine()) != null) {
				if (line.indexOf("window.baidu_time(") != -1) {
					System.out.println(line);
					System.out.println(line.replaceAll("[^0-9]", ""));
					time = Long.parseLong(line.replaceAll("[^0-9]", ""));
					break;
				}
			}
			Calendar can1 = Calendar.getInstance();
			long time1 = time >> 24;
			can1.setTimeInMillis(time1 << 24);
			System.out.println(time1);
			StringBuffer time2 = new StringBuffer();
			StringBuffer str = new StringBuffer();
			time2.append(time1);
			int no = 0;
			str.append(Interfere());
			while (no < time2.length()) {
				str.append(time2.charAt(no));
				str.append(Interfere());
				str.append(time2.charAt(no));
				no++;
			}
			System.out.println(str.toString());
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, "请确认您已连接网络\n并且本程序可以连接到internet");
		}
	}

	private String Interfere() {

		int no1 = (int) (Math.random() * 2 + 1);
		System.out.println(no1);
		StringBuffer str = new StringBuffer();
		str.append(no1);
		while (no1 > 0) {
			no1--;
			char no = (char) (48 + Math.random() * 43);
			str.append(no);
		}
		return str.toString();
	}
}
